<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="5" v-for="(item,index) in panelList" :key="item.icon">
         <com-panel :sendPanel="item"></com-panel>
      </el-col>
    </el-row>
  <el-row class="echarts_main">
    <com-echarts :sendOption="optionData"></com-echarts>
  </el-row>
  </div>
</template>

<script>
// 导入首页接口数据方法
import {api_query} from "../../api/home.js";
 import ComPanel from "../../components/panel";
import ComEcharts from "../../components/comecharts/index.vue";
 export default {
   components:{
     ComPanel,
     ComEcharts
   },
   data(){
     return {
       panelList:[
         {icon:"icon-dingdan1",count:10000,title:"总订单",color:"blue"},
         {icon:"icon-dangrixiaoshoue",count:10000,title:"总销售额",color:"red"},
         {icon:"icon-dingdan",count:10000,title:"今日订单数",color:"yellow"},
         {icon:"icon-a-icon-xiaoshoue-fuben",count:10000,title:"今日销售额",color:"pink"}
       ],
     optionData:{
       title:"数据统计",
       legend:["订单","金额"],
       xData:[],
       series:[]
     }
     }
   },
    mounted(){
      this.query();
    },
    methods:{
     async query(){
      let rst= await api_query();

      let {totalOrder,totalAmount,todayOrder,totayAmount,amountData,orderData,xData}=rst;
        [totalOrder,totalAmount,todayOrder,totayAmount].forEach((item,index)=>{
          this.panelList[index].count=item;
        });
        this.optionData.xData=xData;
        this.optionData.series=[orderData,amountData].map((item,index)=>{
          return {
            name:this.optionData.legend[index],
              type: 'line',
              stack: 'Total',
              data:item
          }
        });
        console.log(this.optionData)
    

      }
    }
  }
</script>

<style lang="less" scoped>
.echarts_main{
  margin-top:30px;
  height:500px;
  background-color:white;
}
</style>